import React from 'react';
import { message } from 'antd';

export default function catchError<T>(Com: React.ComponentType<T>) {
  return class ErrorBoundary extends React.Component<T, {}> {
    componentDidCatch(error: Error, info: React.ErrorInfo) {
      message.error('页面出错了,请刷新页面后再试!');
      console.error(error, info);
    }

    render() {
      return <Com {...this.props} />;
    }
  };
}
